Creating a Text Label

This example demonstrates how to create a label with a text label style in a specific position on the terrain. This example uses the IPosition80 (Copy, Pitch), ILabelStyle80 (FontName, Italic, BackgroundColor, Scale), ITerrainLabel80, ICreator80 (CreatePosition, CreateLabelStyle, CreateTextLabel), IColor80 (FromBGRColor, SetAlpha, and INavigate80 (FlyTo) properties and methods.

 

private void CreateLabel()

        {

            string tMsg = String.Empty;

            IPosition80 cPos = null;

            ILabelStyle80 cLabelStyle = null;

            ITerrainLabel80 cTextLabel = null;

 

            try

            {

                //

                // A. Instantiate TerraExplorer Object

                //

                var SGWorld = new SGWorld80();

 

                //

                // B.  Create position for label

                //

                {

                    // B1. Set position  input parameters (San Francisco shore)

                    double dXCoord = -122.49460;

                    double dYCoord = 37.78816;

                    double dAltitude = 100.0;

                    AltitudeTypeCode eAltitudeTypeCode = AltitudeTypeCode.ATC_TERRAIN_RELATIVE;

                    double dYaw = 0.0;

                    double dPitch = 0.0;

                    double dRoll = 0.0;

                    double dDistance = 500;

 

                    // B2. Create Position

                    cPos = SGWorld.Creator.CreatePosition(dXCoord, dYCoord, dAltitude, eAltitudeTypeCode, dYaw, dPitch, dRoll, dDistance);

                }

 

                //

                // C.  Create label style for label

                //

                {

                    // C1. Set label style input parameters

                    SGLabelStyle eLabelStyle = SGLabelStyle.LS_DEFAULT;

 

                    // C2. Create label style

                    cLabelStyle = SGWorld.Creator.CreateLabelStyle(eLabelStyle);

 

                    // C3. Change label style settings

                    {

                        uint nBGRValue = 0xFF0000;  // Blue

                        double dAlpha = 0.5;        // 50% opacity

                        var cBackgroundColor = cLabelStyle.BackgroundColor; // Get label style background color

                        cBackgroundColor.FromBGRColor(nBGRValue);               // Set background to blue

                        cBackgroundColor.SetAlpha(dAlpha);                      // Set transparency to 50%

                        cLabelStyle.BackgroundColor = cBackgroundColor;         // Set label style background color

                        cLabelStyle.FontName = "Arial";                         // Set font name to Arial

                        cLabelStyle.Italic = true;                              // Set label style font to italic

                        cLabelStyle.Scale = 3;                                  // Set label style scale

                    }

                }

 

                //

                // D. Create text label using label style

                //

                {

                    // D1. Set label style params

                    string tText = "Skyline";

 

                    // D2. Create label style

                    cTextLabel = SGWorld.Creator.CreateTextLabel(cPos, tText, cLabelStyle, string.Empty, "TextLabel");

                }

 

                //

                // E. FlyTo text label

                //

                {

                    var cFlyToPos = cPos.Copy();

                    cFlyToPos.Pitch = -89.0; // Set camera to look downward on text label

                    SGWorld.Navigate.FlyTo(cFlyToPos, ActionCode.AC_FLYTO);

                }

            }

            catch (Exception ex)

            {

                tMsg = String.Format("CreateLabelButton_Click Exception: {0}", ex.Message);

                MessageBox.Show(tMsg);

            }

        }